import type { Directive } from 'vue'
import { isObject } from '/@/utils/isObject'

interface scrollScreenOptionsTypes {
  left: number
  top: number
  run?: boolean
}
function scrollRun(options?: scrollScreenOptionsTypes) {
  window.scrollTo({
    ...options,
    behavior: 'smooth',
  })
}
const scrollScreen: Directive = {
  mounted(el, bind) {
    isObject(bind.value)
    bind.value?.run && scrollRun(bind.value)
  },
  updated(el, bind) {
    isObject(bind.value)
    bind.value?.run && scrollRun(bind.value)
  },
}

export { scrollScreen }
export type { scrollScreenOptionsTypes }
